package com.chenchao.designer.decorator;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/18 20:42
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javadesigner.decorator.Test2.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 */
public class Test2 {
    public static void main(String[] args) {
        Robot robot01 = new Robot01();
        Robot robot02 = new MyRobot01_01(robot01);
        Robot robot03 = new MyRobot01_02(robot02);
        Robot robot04 = new MyRobot01(robot03) {
            @Override
            public void doSomething() {
                super.doSomething();
                System.out.println("我还会打人");
            }
        };
        robot01.doSomething();
        System.out.println("+++++++++++");
        robot02.doSomething();
        System.out.println("+++++++++++");
        robot03.doSomething();
        System.out.println("+++++++++++");
        robot04.doSomething();
    }
}
interface Robot{
    void doSomething();
}
class Robot01 implements Robot{

    @Override
    public void doSomething() {
        System.out.println("我会洗衣做饭");
    }
}
 abstract class MyRobot01 implements Robot{
    Robot robot;

    public MyRobot01(Robot robot) {
        this.robot = robot;
    }

    @Override
    public void doSomething() {
        robot.doSomething();
    }
}
class MyRobot01_01 extends MyRobot01{

    public MyRobot01_01(Robot robot) {
        super(robot);
    }

    @Override
    public void doSomething() {
        super.doSomething();
        System.out.println("我还会唱歌");
    }
}
class MyRobot01_02 extends MyRobot01{

    public MyRobot01_02(Robot robot) {
        super(robot);
    }

    @Override
    public void doSomething() {
        super.doSomething();
        System.out.println("我还会跳舞");
    }
}